package br.jcrsistemas.componentes;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.text.ParseException;

import javax.swing.text.MaskFormatter;

import org.jdesktop.swingx.JXDatePicker;


public class SysDatePicker extends JXDatePicker {

    private MaskFormatter formatador;
    private boolean aceitaDataSuperiorAtual = true;
    private boolean enterChangeFocus = true;

    public SysDatePicker() throws ParseException {
        super();
        //getEditor().setFormatterFactory(tf)
        getEditor().setInputVerifier(new DataInputVerifier(getEditor(), isAceitaDataSuperiorAtual()));
        setFormats(new String[]{"dd/MM/yyyy"});
        addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                if(e.getKeyCode() == KeyEvent.VK_ENTER && enterChangeFocus) {
                    transferFocus();
                }
            }
            
        });


    }

    public void setEnterChangeFocus(boolean enterChangeFocus) {
        this.enterChangeFocus = enterChangeFocus;
    }
    
    public boolean getEnterChangeFocus() {
        return this.enterChangeFocus;
    }
    

    public void setAceitaDataSuperiorAtual(boolean aceitaDataSuperiorAtual) {
        this.aceitaDataSuperiorAtual = aceitaDataSuperiorAtual;
        getEditor().setInputVerifier(new DataInputVerifier(getEditor(), isAceitaDataSuperiorAtual()));
    }

    public boolean isAceitaDataSuperiorAtual() {
        return aceitaDataSuperiorAtual;
    }

    private class teste extends MaskFormatter {
    }
}
